using Dapper;
using Read.Models;

namespace Read.Services
{
    public class AccessService : BaseService
    {
        /// <summary>
        /// 查询该角色Id是否有操作该控制器方法的权限
        /// </summary>
        /// <returns></returns>
        public AccessModel getAccess(string RoleId, string Controller, string Action)
        {
            string sql = $"SELECT A.* FROM `{Tables.Access}` AS A LEFT JOIN `{Tables.Node}` AS N ON A.NodeId = N.id  WHERE RoleId = @RoleId AND N.Controller=@Controller AND N.Action=@Action";
            var access = connection.QueryFirstOrDefault<AccessModel>(sql, new { RoleId = RoleId, Controller = Controller, Action = Action });
            return access;
        }
    }
}